package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {

	@FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[4]/a")
	public WebElement menuLogoutLink;
	
	@FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[1]/a")
	public WebElement menuHomeLink;
	
	@FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[2]/a")
	public WebElement menuMyProfileLink;
	
	@FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[3]/a")
	public WebElement menuUserManagementLink;

	public boolean isOnUserManagementPage() {
		return menuUserManagementLink.isSelected();
	}
		
	public boolean isOnThisPage() {
		return menuLogoutLink.isDisplayed();
	}
	
	public void logout() {
		menuLogoutLink.click();
		driver.switchTo().alert().accept();
	}

	
	@Override
	void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin", "admin");
	}

	public ManagementPage goToUserManagementPage() {
		menuUserManagementLink.click();
		return MyPageFactory.getPage(driver, ManagementPage.class);
	}
}
